<?php
/*
	用户端公共文件，访问用户端时默认加载
*/
defined('BY_JYA') or exit('error');
//扫码进入的
if($_RQ['fromuser'] && $_RQ['action']=='team.myshop'){
	$this->session('sao_fromuser',$_RQ['fromuser']);
}
if($_RQ['action']=='team.login'){
	return '';
}
$return['ischecklogin']=$this->model('team')->checklogin();
$return['pluginset']=$this->plugin_setting('setting');
if($_RQ['is_access'] && $_RQ['action']!='team.login' && $_RQ['action']!='team.apply' && $_RQ['action'] !='team.myshop' && $_RQ['action'] !='team.info'){
	$member=$this->model('team')->checkmember('',true);
}elseif($_RQ['action'] !='team.myshop' && $_RQ['action']!='team.apply' && $_RQ['action']!='team.login'){
	$member=$this->model('team')->checkmember('',false);
}
if($_SESSION['container']=='wxapp' && !$_SESSION['fromh5wxapp']){
	$iswxapp=1;
}
if(($_RQ['is_access'] || $iswxapp) && (!$member['is_agent'] || $member['stop']) && $_RQ['action'] !='team.myshop' && $_RQ['action'] !='team.apply'){
	//还不是分销商，跳转申请页
	$return['applystatus']=$this->getcolumn('team',array('mid'=>$_SESSION['uid']),'status');
	$apply=$this->get('team',array('mid'=>$_SESSION['uid']),array('id','remark'));
	if($apply['id']){
		$return['apply']=$apply;
		$return['applystatus']=$this->getcolumn('team',array('mid'=>$_SESSION['uid']),'status');
	}
	//判断是否满足申请分销商条件
	$can_apply=true;
	$applyres=$this->model('team')->checkmember();
	$return['desc']=$applyres['desc'];
	$return['now']=$applyres['now'];
	$return['limit']=$applyres['limit'];
	$return['unit']=$applyres['unit'];
	$return['can_apply']=$applyres['can_apply'];
	$return['become_goods']=$applyres['become_goods'];
	$return['member']=$member;
	if($member['agent_id']){
		$return['agent']=model('core/member')->detail($member['agent_id'],array('nickname','avatar'));
		$return['agent_name']=$return['agent']['nickname'];
	}
	$setting=$this->plugin_setting('teampage');
	$return['setting']=$setting;
	$return['setapply']=$this->plugin_setting('teamapply');
	$return['member']=$member?:false;
	$return['item']=model('core/member')->detail($_SESSION['uid'],array('nickname','avatar','realname','mobile','wechat'));
	$return['item']['diyformfields']=$setting['diyformfields']?:array();
	$return['htmls']=$this->template_url('team.apply');
	if($iswxapp){		
		exi('','','jy_ad/team.apply/');
	}
	exi($return);
}


